package #(package).impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.PageHelper;
import #(packageBase).business.mapper.#(className)Mapper;
import #(packageBase).business.service.#(className)Service;
import #(packageBase).common.utils.ResultUtils;
import #(packageBase).model.#(className);
import #(packageBase).param.#(className)QueryParam;
import #(packageBase).vo.JsonResult;

import java.util.List;

/**
* #(comments)接口实现
*
* @author #(author)
* @date #(datetime)
*/
@Slf4j
@Service("#(classname)Service")
public class #(className)ServiceImpl implements #(className)Service {

    @Autowired
    private #(className)Mapper #(classname)Mapper;


    /**
    * 根据id查询#(comments)数据
    * @param #(pk.attrname)
    * @return
    */
    @Override
    public #(className) queryObject(#(pk.attrType) #(pk.attrname)){
        return #(classname)Mapper.queryObject(#(pk.attrname));
    }


    /**
    * 分页查询#(comments)数据
    * @param #(classname)QueryParam
    * @return
    */
    @Override
    public List<#(className)> queryList(#(className)QueryParam #(classname)QueryParam){
        if(#(classname)QueryParam.getPageNum() > 0) {
            PageHelper.startPage(#(classname)QueryParam.getPageNum(), #(classname)QueryParam.getPageSize(), #(classname)QueryParam.getOrderBy());
        }
        return #(classname)Mapper.queryList(BeanUtil.beanToMap(#(classname)QueryParam));
    }


    /**
    * 保存#(comments)数据
    * @param #(classname)
    * @return
    */
    @Override
    public JsonResult save(#(className) #(classname)){
        int count = #(classname)Mapper.save(#(classname));
        return ResultUtils.msg(count);
    }


    /**
    * 修改#(comments)数据
    * @param #(classname)
    * @return
    */
    @Override
    public JsonResult update(#(className) #(classname)){
        int count = #(classname)Mapper.update(#(classname));
        return ResultUtils.msg(count);
    }


    /**
    * 根据#(pk.attrname)删除#(comments)数据
    * @param #(pk.attrname)
    * @return
    */
    @Override
    public JsonResult delete(#(pk.attrType) #(pk.attrname)){
        int count = #(classname)Mapper.delete(#(pk.attrname));
        return ResultUtils.msg(count);
    }


    /**
    * 根据#(pk.attrname)s批量删除#(comments)数据
    * @param #(pk.attrname)s
    * @return
    */
    @Override
    public JsonResult deleteBatch(#(pk.attrType)[] #(pk.attrname)s){
        int count = #(classname)Mapper.deleteBatch(#(pk.attrname)s);
        return ResultUtils.msg(count);
    }

}
